
package jpa;
import java.io.Serializable;
import java.util.Date;
import java.util.Collection;

import javax.persistence.*;

/**
 * JPA Class CustomerJPA
*/
@Entity
@Table(name="practicalcase.customer")

public class CustomerJPA implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	private String nif;
	private String email;
	private String password;
	private String name;
	private String surname;
	private Date birthdate;
	private boolean administrator;
	

	private Collection <OrderJPA> orders;
	private ShippingAddressJPA shippingAddress;

	
	/**
	 * Class constructor methods
	 */
	public CustomerJPA(){
		super();
	}
	
	public CustomerJPA(String nif, String email, String password, String name, String surname, Date birthdate, boolean administrator){		

		this.nif = nif;
		this.email = email;
		this.password = password;
		this.name = name;
		this.surname = surname;
		this.birthdate = birthdate;
		this.administrator = administrator;
		

	}

	public CustomerJPA(String nif, String email, String password, String name, String surname, Date birthdate, boolean administrator, int idShippingAddress){		

		this.nif = nif;
		this.email = email;
		this.password = password;
		this.name = name;
		this.surname = surname;
		this.birthdate = birthdate;
		this.administrator = administrator;
		

	}
	
	public CustomerJPA(String nif, String email, String password, String name, String surname, Date birthdate, boolean administrator, ShippingAddressJPA shippingaddress){		

		this.nif = nif;
		this.email = email;
		this.password = password;
		this.name = name;
		this.surname = surname;
		this.birthdate = birthdate;
		this.administrator = administrator;
		this.shippingAddress=shippingaddress;
		

	}
	/**
	 *  Methods get/set the fields of database
	 *  Id Primary Key field
	 */
	@Id
	public String getNif(){
		return this.nif;
	}
	public void setNif(String nif){
		this.nif = nif;
	}
	public String getEmail(){
		return this.email;
	}
	public void setEmail(String email){
		this.email = email;
	}
	public String getPassword(){
		return this.password;
	}
	public void setPassword(String password){
		this.password = password;
	}
	public String getName(){
		return this.name;
	}
	public void setName(String name){
		this.name = name;
	}
	public String getSurname(){
		return this.surname;
	}
	public void setSurname(String surname){
		this.surname = surname;
	}
	public Date getBirthdate(){
		return this.birthdate;
	}
	public void setBirthdate(Date birthdate){
		this.birthdate = birthdate;
	}
	public boolean getAdministrator(){
		return this.administrator;
	}
	public void setAdministrator(boolean administrator){
		this.administrator = administrator;
	}

	
	
	/**
	 * Methods get/set persistent relationships
	 */
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER )
	@JoinColumn(name = "nif")
	public Collection<OrderJPA> getOrders() {
		return orders;
	}	
	public void setOrders(Collection<OrderJPA> orders) {
 		this.orders = orders; 
	}
	@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER )
	@JoinColumn(name = "idshippingaddress")
	public ShippingAddressJPA getShippingAddress(){
		return this.shippingAddress;
	}
	public void setShippingAddress(ShippingAddressJPA shippingAddress){
		this.shippingAddress = shippingAddress;
	}
}
